﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using BLL.教师操作BLL;
using Model;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Configuration;
using NCRE学生考试端V1._0;
using NCRE学生考试端V1._0.教师端操作类;
using System.ComponentModel;
using System.Drawing;


namespace NCRE学生考试端V1._0
{
    public partial class frmTeacherManagerMain : Form
    {
        public frmTeacherManagerMain()
        {
            InitializeComponent();
        }

        #region 定义
        //定义一个学生分数的逻辑类
        StudentScoreBLL studentscorebll = new StudentScoreBLL();

        //定义一个学生的实体用来传递学生信息
        StudentInfoEntity studentinfo = new StudentInfoEntity();       

        //定义一个StudentBindPaperTypeBLL类
        StudentBindPaperTypeBLL studentBindPaperType = new StudentBindPaperTypeBLL();
        //定义一个StudentBindPaperTypeEntity类
        StudentBindPaperTypeEntity studentBindPaperTypeEntity = new StudentBindPaperTypeEntity();

        TimeEntity timeEntity = new TimeEntity();
        ControlIpEntity controlIpEntity = new ControlIpEntity();
        StudentInfoEntity studentIngo = new StudentInfoEntity();
        CollegeEntity college = new CollegeEntity();

        AddStudentBLL addstudent = new AddStudentBLL();
        #endregion

        #region 分页功能-吕德彪-2018
        DataTable table1 = new DataTable();
        //定义分页需要的变量
        int cRows = 0;
        int RowCurrent = 0;
        int cPages = 0;
        int PageCurrent = 0;
        const int PageSize = 10;
        int record = 0;


        private void LoadData()
        {
            if (PageCurrent == 1)
            {
                ts_PagePrevious.Enabled = false;
            }
            else
            {
                ts_PagePrevious.Enabled = true;
            }
            if (cPages == PageCurrent)
            {
                ts_PageNext.Enabled = false;
            }
            else
            {
                ts_PageNext.Enabled = true;
            }
            
            ts_PagePostion.Text = PageCurrent.ToString();
            ts_Pages.Text = cPages.ToString();
            int startRow = (PageCurrent - 1) * PageSize;
            int endRow = PageCurrent == cPages ? cRows : PageCurrent * PageSize;
            DataTable dtTemp = table1.Clone();
            if (table1.Rows.Count != 0)
            {
                for (int i = startRow; i < endRow; i++)
                {
                    dtTemp.ImportRow(table1.Rows[i]);
                }
                bindingSource1.DataSource = dtTemp;
                dgvScore.DataSource = bindingSource1;

            }

        }

        private void bindingNavigator1_ItemClicked_1(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "上一页")
            {
                ts_PageNext.Enabled = true;
                if (PageCurrent == 1)        
                {
                    ts_PagePrevious.Enabled = false;
                    MessageBox.Show("已经是第一页了");
                    return;
                }
                PageCurrent--;
                LoadData();
            }
            if (e.ClickedItem.Text == "下一页")
            {                                             
                ts_PagePrevious.Enabled = true;
                //if (PageCurrent == PageSize)
                if (PageCurrent == cPages)  //最后一页——修改人——薛帅行——2018年12月30号21点27分
                {
                    ts_PageNext.Enabled = false;
                    MessageBox.Show("已经是最后一页了");
                    return;
                }
                PageCurrent++;
                LoadData();
            }
        }

        private void bindingNavigatorMoveFirstPage_Click_1(object sender, EventArgs e)
        {
            if (PageCurrent == 1)
            {
                MessageBox.Show("已经是第一页了");
                return;
            }
            else
            {
                PageCurrent = 1;
                bindingNavigatorMoveFirstPage.Enabled = false;
                bindingNavigatorMoveLastPage.Enabled = true;
                ts_PagePrevious.Enabled = false;
                ts_PageNext.Enabled = true;
                LoadData();
            }
        }

        private void bindingNavigatorMoveLastPage_Click_1(object sender, EventArgs e)
        {
            //if (PageCurrent == PageSize)
            if (PageCurrent == cPages)  //最后一页——修改人——薛帅行——2018年12月30号21点27分
            {
                MessageBox.Show("已经是最后一页了");
                return;
            }
            else
            {
                PageCurrent = cPages;
                bindingNavigatorMoveFirstPage.Enabled = true;
                bindingNavigatorMoveLastPage.Enabled = false;
                ts_PagePrevious.Enabled = true;
                ts_PageNext.Enabled = false;
                LoadData();
            }
        }

        private void ts_PagePostion_TextChanged_1(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(ts_PagePostion.Text) > 0 && Convert.ToInt32(ts_PagePostion.Text) <= cPages)
                {
                    PageCurrent = Convert.ToInt32(ts_PagePostion.Text);
                    LoadData();
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (System.Exception ex)
            {
                PageCurrent = 1;
                LoadData();
            }
        }        
        #endregion

        #region 窗体加载-吕德彪-2018
        /// <summary>
        /// 窗体加载-吕德彪-2018
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmTeacherManagerMain_Load(object sender, EventArgs e)
        {

            #region 设置开始时间提前两小时，截至时间晚两小时
            dateTimePicker1.Value = DateTime.Now.AddHours(-2);
            dateTimePicker2.Value = DateTime.Now.AddHours(2);
            #endregion

            #region 控件是否显示
            label5.Visible = false;
            label6.Visible = false;
            label13.Visible = false;
            label15.Visible = false;
            label19.Visible = false;
            label21.Visible = false;
            label22.Visible = false;
            lblCount1.Visible = false;
            lblCountAll1.Visible = false;
            lblSubmitted.Visible = false;
            lblNotUpload.Visible = false;
            #endregion

            #region 状态下拉框赋值
            string[] filename = { "在线", "已交卷", "未上传" ,"全部"};
            cboStatus.Items.AddRange(filename);
            cboStatus.SelectedIndex = 0;
            #endregion

            #region 考场下拉框中加载信息
            DataTable dt_IP = new DataTable();             
            dt_IP = addstudent.SelectIP();
            List<String> Iplist = new List<string>();  
                     
            foreach (DataRow item in dt_IP.Rows)
            {
                Iplist.Add(item["ipName"].ToString());
            }
            Iplist.Add("全部");
            if (dt_IP != null && dt_IP.Rows.Count > 0)
            {
                cboPlace.SelectedIndexChanged -= new EventHandler(cboPlace_SelectedIndexChanged);
                cboPlace.DataSource = Iplist;
                cboPlace.Text = "全部";
                cboPlace.SelectedIndexChanged += new EventHandler(cboPlace_SelectedIndexChanged);
            }

            #endregion

            #region 加载所有正在考试学生
            studentBindPaperTypeEntity.TimeTamp = dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss");
            studentBindPaperTypeEntity.IsUse = Convert.ToDouble(ToName(cboStatus.Text.Trim()));
            table1 = studentBindPaperType.AllOnlineStudent(studentBindPaperTypeEntity);
            if (table1.Rows.Count == 0)
            {
                dgvScore.DataSource = null;
                return;             
            }
            else
            {               

                cRows = table1.Rows.Count;
                cPages = cRows % PageSize == 0 ? cRows / PageSize : cRows / PageSize + 1;
                PageCurrent = 1;
                toolStripLabel3.Text = cRows.ToString();
                LoadData();

                dgvScore.Columns[0].HeaderText = "学号";
                dgvScore.Columns[1].HeaderText = "类型";
                dgvScore.Columns[2].HeaderText = "考试状态";
                dgvScore.Columns[3].HeaderText = "学院";
                dgvScore.Columns[4].HeaderText = "时间";
                dgvScore.Columns[5].HeaderText = "ip号";
                dgvScore.Columns[6].HeaderText = "考场";
                dgvScore.Columns[7].HeaderText = "姓名";
                dgvScore.Columns[8].HeaderText = "专业";
                dgvScore.Columns[9].HeaderText = "班级";
                dgvScore.Columns[10].HeaderText = "模式";
                dgvScore.AllowUserToAddRows = false;
            }
            #endregion

            #region 显示人数
            //获取时间
            studentBindPaperTypeEntity.TimeTamp = dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss");
            timeEntity.EndDateTime = dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss");

            //本场考试考生在线考生人数
            table = studentBindPaperType.OnLineCount(studentBindPaperTypeEntity, timeEntity);
            lblCount.Text = table.Rows[0][0].ToString();

            //本场所有考试人数
            allCountTable = studentBindPaperType.AllCount(studentBindPaperTypeEntity, timeEntity);
            lblCountAll.Text = allCountTable.Rows[0][0].ToString();

            //lblCount1.Text = "0";
            //lblCountAll1.Text = "0";
            #endregion


         


        }
        #endregion                                   

        #region 将下拉框中的汉字转换成数据库的字段-吕德彪-2018
        public string ToName(string combo)
        {           
            switch (combo)
            {
                case "在线":
                    return "1";
                case "已交卷":
                    return "0";
                case "未上传":
                    return "2";
                default:
                    return "";
            }
        }
        #endregion        
          
        
        #region 导出
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (table1.Rows.Count == 0)
            {
                MessageBox.Show("该学院无数据", "提示", MessageBoxButtons.OK,
                MessageBoxIcon.Warning);
            }
            else
            {
                dgvScore.DataSource = table1;
                ExcelExport excelexcport = new ExcelExport();
                excelexcport.setExcel(dgvScore, cboPlace.GetItemText(cboPlace.Text));

                cRows = table1.Rows.Count;
                cPages = cRows % PageSize == 0 ? cRows / PageSize : cRows / PageSize + 1;
                PageCurrent = 1;
                LoadData();
            }
        }
        #endregion

        #region  下载考试答卷
        //private void btnDownLoad_Click(object sender, EventArgs e)
        //{
        //    if (dgvScore.Rows.Count == 0)
        //    {
        //        MessageBox.Show("无答题信息，请重新选择后下载");
        //    }
        //    else
        //    {


        //        for (int i = 0; i < dgvScore.Rows.Count; i++)
        //        {
        //            string s = dgvScore.Rows[i].Cells["日期"].Value.ToString();
        //            if (s == "")
        //            {

        //            }
        //            else
        //            {
        //                string m = Regex.Replace(dgvScore.Rows[i].Cells["日期"].Value.ToString(), @"[^\d]*", "");

        //                string allname = dgvScore.Rows[i].Cells["学号"].Value.ToString() + "-" + m;

        //                MongoHelper mh = new MongoHelper("NCRE3");

        //                //下载
        //                mh.DownLoad(allname + ".zip", studentinfo.CollegeID);
        //                if (File.Exists(@"D:\" + allname + @".zip"))
        //                {
        //                    MessageBox.Show(@"D:\" + allname + @".zip" + "已经存在,请先删除后再下载！");
        //                }
        //                else
        //                {
        //                    File.Move(allname + @".zip", @"D:\" + allname + @".zip");

        //                    MessageBox.Show("文件下载成功，默认下载到D盘，点击确定打开压缩文件");
        //                    Process.Start(@"D:\" + allname + @".zip");
        //                }
        //            }
        //        }
        //    }
        //}
        #endregion

        #region 再考人数实时更新，暂时关闭
        //private void timer1_Tick_1(object sender, EventArgs e)
        //{         
        //    try
        //    {
        //        lblCount.Text = table.Rows[0][0].ToString();
        //        lblCountAll.Text = allCountTable.Rows[0][0].ToString();
        //    }
        //    catch
        //    {
        //        return;
                
        //    }
        //    //lblCount1.Text = examPlaceOnlineTable.Rows[0][0].ToString();
        //    //lblCountAll1.Text = examPlaceTable.Rows[0][0].ToString();
        //    //lblSubmitted.Text = submittedTable.Rows[0][0].ToString();
        //    //lblNotUpload.Text = UnUploadTable.Rows[0][0].ToString();
        //}        
        #endregion

        #region 模糊搜索未交卷学生 --吕德彪-2018
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text == "" || txtSearch.Text == "请输入学号/姓名/学院/专业/班级查询在线考生")
            {
                #region  如果搜索框为空，加载所有正在考试学生
                table1 = studentBindPaperType.AllOnlineStudent(studentBindPaperTypeEntity);
                if (table1.Rows.Count == 0)
                {
                    dgvScore.DataSource = null;
                }
                else
                {                                     

                    cRows = table1.Rows.Count;
                    cPages = cRows % PageSize == 0 ? cRows / PageSize : cRows / PageSize + 1;
                    PageCurrent = 1;
                    toolStripLabel3.Text = cRows.ToString();
                    LoadData();

                    dgvScore.Columns[0].HeaderText = "学号";
                    dgvScore.Columns[1].HeaderText = "类型";
                    dgvScore.Columns[2].HeaderText = "考试状态";
                    dgvScore.Columns[3].HeaderText = "学院";
                    dgvScore.Columns[4].HeaderText = "时间";
                    dgvScore.Columns[5].HeaderText = "ip号";
                    dgvScore.Columns[6].HeaderText = "考场";
                    dgvScore.Columns[7].HeaderText = "姓名";
                    dgvScore.Columns[8].HeaderText = "专业";
                    dgvScore.Columns[9].HeaderText = "班级";
                    dgvScore.Columns[10].HeaderText = "模式";
                    dgvScore.AllowUserToAddRows = false;
                }
                #endregion
            }
            else
            {
                #region 进行模糊查询
                timeEntity.Search = txtSearch.Text.Trim();

                table1 = studentBindPaperType.NotSubmitStudent(timeEntity);
                if (table1.Rows.Count == 0)
                {
                    dgvScore.DataSource = null;
                    label11.Visible = true;
                }
                else
                {
                    cRows = table1.Rows.Count;
                    cPages = cRows % PageSize == 0 ? cRows / PageSize : cRows / PageSize + 1;
                    PageCurrent = 1;
                    LoadData();
                    dgvScore.Columns[0].HeaderText = "学号";
                    dgvScore.Columns[1].HeaderText = "类型";
                    dgvScore.Columns[2].HeaderText = "考试状态";
                    dgvScore.Columns[3].HeaderText = "学院";
                    dgvScore.Columns[4].HeaderText = "时间";
                    dgvScore.Columns[5].HeaderText = "ip号";
                    dgvScore.Columns[6].HeaderText = "考场";
                    dgvScore.Columns[7].HeaderText = "姓名";
                    dgvScore.Columns[8].HeaderText = "专业";
                    dgvScore.Columns[9].HeaderText = "班级";
                    dgvScore.Columns[10].HeaderText = "模式";
                    dgvScore.AllowUserToAddRows = false;
                }
                #endregion
            }
            
        }
        #endregion

        #region 级联菜单 修改人：李金颖-窗体单一显示-2018-12-8 11:24:09
        private void 配置分数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAllSore.GetInstance().ShowDialog();
        }

        private void 查询分数详情ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmScoreDetail.GetInstance().ShowDialog();
            //注意：解决方案中，该窗体名称为frmShowMessage
        }

        //private void 单个学生配题ToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    frmSingleStu.GetInstance().ShowDialog();
        //}

        private void 单个学生配题ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmSingleStu.GetInstance().ShowDialog();
        }

        //private void 查看学生答题文件ToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    frmQueryStudentRecord.GetInstance().ShowDialog();
        //}

        private void 查询历史成绩ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmShowHistoryMessage.GetInstance().ShowDialog();
        }

        private void 批量导入学生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAddGroupStudent.GetInstance().ShowDialog();
        }

        private void 低分学生成绩信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmShowNoScore.GetInstance().ShowDialog();
        }

        private void 查看日志ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmLogInfo.GetInstance().ShowDialog();
        }

        private void frmTeacherManagerMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Environment.Exit(0);
        }

        //private void 学生端显示成绩ToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    FrmStudentSetting.GetInstance().ShowDialog();
        //}

        private void 学生端系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmStudentSetting.GetInstance().ShowDialog();
        }
        private void 添加单个学生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAddStudent.GetInstance().ShowDialog();
        }

        private void 查询成绩ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDisplayScore.GetInstance().ShowDialog();
        }

        private void IP管理ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmIPManagement.GetInstance().ShowDialog();
        }
        private void 配置各个题型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAddExamQuestion.GetInstance().ShowDialog();
        }
        
        private void 二维码验证ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            验证码登录.frmQRcode.GetInstance().ShowDialog();
        }
        private void 考试成绩推送ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmExamScore.GetInstance().ShowDialog();
        }

        #endregion

        #region
        private void txtTime_TextChanged(object sender, EventArgs e)
        {
            //studentBindPaperTypeEntity.TimeTamp = txtBeginDate.Text.Trim().Substring(0, 10) + " " + txtBeginTime.Text.Trim();
            studentBindPaperTypeEntity.TimeTamp = dateTimePicker1.Value.ToString();
            //加载所有正在考试学生
            table1 = studentBindPaperType.AllOnlineStudent(studentBindPaperTypeEntity);
            if (table1.Rows.Count > 0)
            {
                for (int i = 0; i < table1.Rows.Count; i++)
                {
                    cRows = table1.Rows.Count;
                    cPages = cRows % PageSize == 0 ? cRows / PageSize : cRows / PageSize + 1;
                    PageCurrent = 1;
                    LoadData();

                    dgvScore.Columns[0].HeaderText = "学号";
                    dgvScore.Columns[1].HeaderText = "类型";
                    dgvScore.Columns[2].HeaderText = "状态";
                    dgvScore.Columns[3].HeaderText = "学院ID";
                    dgvScore.Columns[4].HeaderText = "时间";
                    dgvScore.Columns[5].HeaderText = "ip号";
                    dgvScore.Columns[6].HeaderText = "考场";
                    dgvScore.Columns[7].HeaderText = "姓名";
                    dgvScore.Columns[8].HeaderText = "专业";
                    dgvScore.Columns[9].HeaderText = "班级";
                    dgvScore.AllowUserToAddRows = false;

                }

            }
            else
            {
                MessageBox.Show("没有正在考试的学生！");
                dgvScore.DataSource = null;
                return;
            }
        }

        public static string shijian { get; set; }
        public static string time { get; set; }
        private void btnQuery_Click(object sender, EventArgs e)
        {
            //shijian = txtBeginDate.Text.Trim().Substring(0, 10);
            //time = txtBeginTime.Text.Trim();
            shijian = dateTimePicker1.Value.ToLongDateString();
            time = dateTimePicker2.Value.ToLongTimeString();
            frmShowOnLineStd frmshowonlinestd = new frmShowOnLineStd();
            frmshowonlinestd.Show();
        }

        #endregion

        #region txtSearch框里内容获取焦点-吕德彪-2018 
        private void txtSearch_MouseDown(object sender, MouseEventArgs e)
        {
            label11.Visible = false;
            txtSearch.SelectionStart = 0;
            txtSearch.SelectionLength = txtSearch.Text.Length;
            txtSearch.SelectAll();
        }


        #endregion

        #region 考场下拉框事件-吕德彪-2018 修改人：刘檬-记录为空窗体显示-2018-12-11 8:35:00
        DataTable table = null;
        DataTable allCountTable = null;
        DataTable examPlaceOnlineTable = null;
        DataTable examPlaceTable = null;
        DataTable submittedTable = null;
        DataTable UnUploadTable = null;
        private void cboPlace_SelectedIndexChanged(object sender, EventArgs e)
        {
            studentBindPaperTypeEntity.TimeTamp = dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss");
            timeEntity.EndDateTime = dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss");

            String ipName = "";

            if (cboPlace.Text == "全部")
            {
                #region 控件是否显示
                label5.Visible = false;
                label6.Visible = false;
                label13.Visible = false;
                label15.Visible = false;
                label19.Visible = false;
                label21.Visible = false;
                label22.Visible = false;
                lblCount1.Visible = false;
                lblCountAll1.Visible = false;
                lblSubmitted.Visible = false;
                lblNotUpload.Visible = false;
                #endregion


                if (cboStatus.Text == "全部")
                {
                    table1 = studentBindPaperType.AllStudent(studentBindPaperTypeEntity, timeEntity);
                }
                else
                {
                    studentBindPaperTypeEntity.IsUse = Convert.ToDouble(ToName(cboStatus.Text.Trim()));
                    //查询所有在线或交卷的学生
                    table1 = studentBindPaperType.AllOnlineStudent(studentBindPaperTypeEntity);
                }
                if (table1.Rows.Count == 0)
                {
                    dgvScore.DataSource = null;
                    MessageBox.Show("没有" + cboStatus.Text + "学生！");
                    return;
                }
                else
                {
                    #region dategridview分页显示               
                    cRows = table1.Rows.Count;
                    cPages = cRows % PageSize == 0 ? cRows / PageSize : cRows / PageSize + 1;
                    PageCurrent = 1;
                    toolStripLabel3.Text = cRows.ToString();
                    LoadData();

                    dgvScore.Columns[0].HeaderText = "学号";
                    dgvScore.Columns[1].HeaderText = "类型";
                    dgvScore.Columns[2].HeaderText = "考试状态";
                    dgvScore.Columns[3].HeaderText = "学院";
                    dgvScore.Columns[4].HeaderText = "时间";
                    dgvScore.Columns[5].HeaderText = "ip号";
                    dgvScore.Columns[6].HeaderText = "考场";
                    dgvScore.Columns[7].HeaderText = "姓名";
                    dgvScore.Columns[8].HeaderText = "专业";
                    dgvScore.Columns[9].HeaderText = "班级";
                    dgvScore.Columns[10].HeaderText = "模式";
                    dgvScore.AllowUserToAddRows = false;
                    #endregion
                }
                #region 显示人数
                //本场考试考生在线考生人数
                table = studentBindPaperType.OnLineCount(studentBindPaperTypeEntity, timeEntity);
                lblCount.Text = table.Rows[0][0].ToString();

                //本场所有考试人数
                allCountTable = studentBindPaperType.AllCount(studentBindPaperTypeEntity, timeEntity);
                lblCountAll.Text = allCountTable.Rows[0][0].ToString();

                lblSubmitted.Text = "";
                lblNotUpload.Text = "";
                return;
                #endregion
            }
            else
            {
                ipName = cboPlace.Text;

                #region 控件是否显示
                label5.Visible = true;
                label6.Visible = true;
                label13.Visible = true;
                label15.Visible = true;
                label19.Visible = true;
                label21.Visible = true;
                label22.Visible = true;
                lblCount1.Visible = true;
                lblCountAll1.Visible = true;
                lblSubmitted.Visible = true;
                lblNotUpload.Visible = true;

                label14.Visible = false;
                label12.Visible = false;
                lblCountAll.Visible = false;
                label17.Visible = false;
                lblCount.Visible = false;
                #endregion

                if (cboStatus.Text == "全部")
                {
                    table1 = studentBindPaperType.PlaceAllStudent(studentBindPaperTypeEntity, ipName, timeEntity);
                }
                else
                {
                    studentBindPaperTypeEntity.IsUse = Convert.ToDouble(ToName(cboStatus.Text.Trim()));
                    table1 = studentBindPaperType.OnLineStudentBy(studentBindPaperTypeEntity, ipName, timeEntity);
                }
                if (table1.Rows.Count == 0)
                {
                    dgvScore.DataSource = null;
                    MessageBox.Show(cboPlace.Text+ "没有" + cboStatus.Text + "的"+ "学生！");
                    return;
                }
                else                                 
                {

                    #region dategridview分页显示
                    cRows = table1.Rows.Count;
                    cPages = cRows % PageSize == 0 ? cRows / PageSize : cRows / PageSize + 1;
                    PageCurrent = 1;
                    toolStripLabel3.Text = cRows.ToString();
                    LoadData();

                    dgvScore.Columns[0].HeaderText = "学号";
                    dgvScore.Columns[1].HeaderText = "类型";
                    dgvScore.Columns[2].HeaderText = "考试状态";
                    dgvScore.Columns[3].HeaderText = "学院";
                    dgvScore.Columns[4].HeaderText = "时间";
                    dgvScore.Columns[5].HeaderText = "ip号";
                    dgvScore.Columns[6].HeaderText = "考场";
                    dgvScore.Columns[7].HeaderText = "姓名";
                    dgvScore.Columns[8].HeaderText = "专业";
                    dgvScore.Columns[9].HeaderText = "班级";
                    dgvScore.Columns[10].HeaderText = "模式";
                    dgvScore.AllowUserToAddRows = false;
                    #endregion
                }
                #region 显示人数
                //本考场在线考生人数
                examPlaceOnlineTable = studentBindPaperType.ExamPlaceOnlineCount(studentBindPaperTypeEntity, timeEntity, ipName);
                lblCount1.Text = examPlaceOnlineTable.Rows[0][0].ToString();

                //查询该考场的考生人数
                examPlaceTable = studentBindPaperType.ExamPlaceCount(studentBindPaperTypeEntity, timeEntity, ipName);
                lblCountAll1.Text = examPlaceTable.Rows[0][0].ToString();

                //查询该考场已交卷考生人数
                submittedTable = studentBindPaperType.SubmittedCount(studentBindPaperTypeEntity, timeEntity, ipName);
                lblSubmitted.Text = submittedTable.Rows[0][0].ToString();

                //查询该考场文件未上传成功考生人数
                UnUploadTable = studentBindPaperType.UnUploadCount(studentBindPaperTypeEntity, timeEntity, ipName);
                lblNotUpload.Text = UnUploadTable.Rows[0][0].ToString();
                #endregion
            }
        }



        #endregion
    }
}
